﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Tour.Linq.TourDBML;
public partial class AdminManager_Login : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ibtn_Login_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (CheckEnterInfo())
            {
                //MyTourDataContext context = new MyTourDataContext();
                var admin = (from a in TourContext.Admin
                             where a.UserName == txtUserName.Text && a.Password == txtPassword.Text
                             select a);
                if (admin.Count() <= 0)
                {
                    _Message = "用户名密码错误";
                }
                else
                {
                    Response.Cookies.Add(new HttpCookie("Admin", admin.First().ID.ToString()));
                    _Message = "登录成功";
                    if (Request["returnUrl"] != null)
                    {
                        _ReturnUrl = Request["returnUrl"].ToString();
                    }
                    else
                    {
                        _ReturnUrl = "Default.aspx";
                    }
                }
            }
        }
        catch
        {
            throw new Exception(TourContext.Connection.ConnectionString);
        }
    }
}
